<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.lmpop.frame.util.PageTools"%>
<%@page import="com.lmpop.trade.ti_teamorder.Ti_groupVoucherInfo"%>
<%
	request.setCharacterEncoding("UTF-8");
	Ti_groupVoucherInfo groupVoucherInfo = new Ti_groupVoucherInfo();
	Map params = new Hashtable();

	String _voucher_code = "", user_id = "",_enabled="";
	if (request.getParameter("_voucher_code") != null
			&& !request.getParameter("_voucher_code").equals("")) {
		_voucher_code = request.getParameter("_voucher_code");
		params.put("voucher_code", _voucher_code);
	}
	if (request.getParameter("_enabled") != null
			&& !request.getParameter("_enabled").equals("")) {
		_enabled = request.getParameter("_enabled");
		params.put("enabled", _enabled);
	}
	String iStart = "0";
	int counter = 0;
	List list = null;
	int limit = 10;
	if (request.getParameter("iStart") != null)
		iStart = request.getParameter("iStart");

	counter = groupVoucherInfo.getCountByObj(params);
	list = groupVoucherInfo.getListByPage(params, Integer
			.parseInt(iStart), limit);

	String pageString = new PageTools().getGoogleToolsBar(counter,
			"index.jsp?voucher_code=" + _voucher_code + "&enabled="+_enabled+"&iStart=",
			Integer.parseInt(iStart), limit);
%>
<html>
	<head>
		<title>团购券管理</title>
	<link href="/program/admin/index/css/style.css" rel="stylesheet" type="text/css">
		<script language="javascript" type="text/javascript"
			src="/program/plugins/calendar/WdatePicker.js"></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/engine.js'></script>
		<script type='text/javascript'
			src='<%=request.getContextPath()%>/dwr/util.js'></script>
		<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/Ti_groupVoucherInfo.js'></script>   
		<script type="text/javascript" src="/js/jquery.js"></script>
	</head>
	<body>
		<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td width="90%">
				<h1>团购券管理</h1>
			</td>
		</tr>
		</table>
	

			<form action="index.jsp" name="voucherForm" method="post">

				<table width="100%" cellpadding="0" cellspacing="0" class="dl_su">
					<tr>
						<td align="left">
							券号:
							<input type="text" class="input" name="_voucher_code"
								id="_voucher_code" maxlength="50" />
							状态:
							<select id="_enabled" name="_enabled">
								<option value="">
									请选择
								</option>
								<option value="0">
									已使用
								</option>
								<option value="1">
									未使用
								</option>
								<option value="2">
									已作废
								</option>
							</select>

							<input type="button" name="Submit" value="搜索"
								onclick="document.voucherForm.submit();" class="button2" />
						
						</td>
					</tr>
				</table>
				<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tablehe">
					<tr><td align="center"><%=pageString%></td></tr>
				</table>
				<table width="100%" cellpadding="0" cellspacing="0" border="0" class="dl_bg">
				<tr>
					<td width="90%">
						<input type="button" name="delInfo" onclick="delIndexInfo()" value="删除" class="buttab"/>
					</td>
					<td>
						总计:<%=counter %>条
					</td>
				</tr>
			</table>
			<table width="100%" cellpadding="1" cellspacing="1" class="listtab" border="0">
							<tr>

								<th width="120">
									券号
								</th>
								<th width="120">
									密码
								</th>
								<th width="100">
									生成时间
								</th>

								<th width="60">
									当前状态
								</th>
								<th width="50">
									操作
								</th>
							</tr>


							<%
								String team_path = "/data/teambuy/";
								String teambuyurl = "";
								int listsize = 0;
								Hashtable nMap = new Hashtable();
								List goodslist = new ArrayList();
								if (null != list && list.size() > 0) {
									listsize = list.size();
									for (int i = 0; i < list.size(); i++) {
										nMap = (Hashtable) list.get(i);
										String order_no = "", in_date = "", enabled = "", tip = "", info_id = "", voucher_code = "",voucher_pwd="";
										if (nMap.get("order_no") != null)
											order_no = nMap.get("order_no").toString();
										if (nMap.get("in_date") != null){
											in_date = nMap.get("in_date").toString();
											in_date=in_date.substring(0,19);
										}
										if (nMap.get("enabled") != null)
											enabled = nMap.get("enabled").toString();
										if (nMap.get("info_id") != null)
											info_id = nMap.get("info_id").toString();
										if (nMap.get("tip") != null)
											tip = nMap.get("tip").toString();
										if (tip.length() > 100)
											tip = tip.substring(0, 100);
										if (nMap.get("voucher_code") != null)
											voucher_code = nMap.get("voucher_code").toString();
										if (nMap.get("voucher_pwd") != null)
											voucher_pwd = nMap.get("voucher_pwd").toString();
							%>
							<tr>
								<td width="70">
									<%=voucher_code%>
								</td>
								<td width="70">
									<input type="text" name="_voucher_pwd" id="_voucher_pwd" maxlength="10" onkeyup="if(/\s/.test(this.value))this.value=''"/>
								</td>
								<td width="150">
									<%=in_date%>
								</td>
								<td width="70">
									
									<%
										if (enabled.equals("0"))
													out.println("已使用");
									%>
									<%
										if (enabled.equals("1"))
													out.println("未使用");
									%>
									<%
										if (enabled.equals("2"))
													out.println("已作废");
									%>
								</td>
								<td width="70">
									<%
										if (enabled.equals("1")){%>
											<a href="#" onclick="updateState('<%=voucher_code%>','0')" >
												<div style="background:url(/program/admin/images/orderbg.jpg) repeat-x;width:57px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">作废券</div>
											</a>
										<%}else{%>
										
											<a href="#" onclick="updateTradeState('<%=voucher_code%>','<%=voucher_pwd%>','<%=order_no%>','1','a_3<%=i %>')" id="a_3<%=i %>" >
												<div style="background:url(/program/admin/images/orderbg.jpg) repeat-x;width:57px;height:20px;line-height:20px;color:#fff;cursor:pointer;text-align:center;">恢复使用</div>
											</a>
										<%}
									%>
									
								</td>
							</tr>

							<%
								}
								}
							%>
						</table>
					<table width="100%" cellpadding="0" cellspacing="0" border="0" class="tablehe">
						<tr><td align="center"><%=pageString %></td></tr>
					</table>
			</form>
			
		<form action="/doTradeReg.do" method="post" name="updateForm">
			<input type="hidden" name="bpm_id" value="9817"/>
			<input type="hidden" name="voucher_code" id="voucher_code" />
			<input type="hidden" name="voucher_pwd" id="voucher_pwd" />
			<input type="hidden" name="user_id" value="<%=user_id %>"/>
			<input type="hidden" name="enabled" id="enabled" value=""/>
		</form>
		<script type="text/javascript">
			function updateState(val,enabled){
				if(document.getElementById("_voucher_pwd").value==""){
					alert("请输入密码");
					return false;
				}else{
					document.getElementById("voucher_pwd").value=document.getElementById("_voucher_pwd").value;
				}
				document.getElementById("voucher_code").value=val;
				document.getElementById("enabled").value=enabled;
				document.updateForm.submit();
			}
			function updateTradeState(code,pwd,orer_no,state,div){
	  			Ti_groupVoucherInfo.updateStateByCode(code,pwd,orer_no,state,function(data){
	  				if(data==1){
	  					document.getElementById(div).innerHTML="操作成功";
	  				}else{
	  					document.getElementById(div).innerHTML="操作失败";
	  				}
				});
	  	}
		</script>
	</body>
</html>